# !/usr/bin python3
# encoding: utf-8 -*-
# @file     : order_actions.py
# @author   : 沙陌 Matongxue_2
# @Time     : 2023/11/12 11:19
# @Copyright: 北京码同学
import time

from common.driver import DriverOperate
from pages.buyer.goods_page import GoodsDetailPage
from pages.buyer.home_page import HomePage


class BuyerOrderActions:

    def buy_now(self,text='沙陌',pay_type='货到付款',receive_time='任意时间'):
        HomePage().send_keys_search(text)\
            .click_shop_btn().click_first_goods()
        # 点击第一个商品后页面新打开一个窗口，所以我们要完成driver的切换
        DriverOperate.globalDriverOperate.switch_to_window()
        checkout_page = GoodsDetailPage().click_buy_now()\
            .click_first_address()
        if pay_type=='货到付款':
            checkout_page.click_huodao_pay()
        elif pay_type == '在线支付':
            checkout_page.click_online_pay()

        if receive_time=='任意时间':
            checkout_page.click_any_time()
        elif receive_time=='仅工作日':
            checkout_page.click_only_work()
        elif receive_time == '仅休息日':
            checkout_page.click_only_not_work()
        result_page = checkout_page.click_submit_order()
        time.sleep(1)
        return result_page.get_order_sn()

    def order_accept_goods(self,order_sn):
        HomePage().click_enter_personcenter()\
            .click_my_order_menu()\
            .send_keys_search(order_sn)\
            .click_search_btn()\
            .click_shouhuo_btn()\
            .click_confirm_btn()

    def return_goos(self,order_sn,user='shamo',desc="这是问题描述"):
        HomePage().click_enter_personcenter()\
        .click_my_order_menu()\
        .send_keys_search(order_sn)\
        .click_search_btn()\
        .click_after_sales()\
        .click_shenqing()\
        .click_returngoods()\
        .select_type()\
        .send_keys_user(user)\
        .select_reason()\
        .send_keys_content(desc)\
        .click_submit()
    def order_comment(self,order_sn,lever_name='好评',content="这是评论内容"):
        HomePage().click_enter_personcenter()\
        .click_my_order_menu()\
        .send_keys_search(order_sn)\
        .click_search_btn()\
        .click_comment()\
        .click_level(lever_name)\
        .send_keys_content(content)\
        .click_submit()